<?php
    // Make connection with the database:
	include_once('../core/init.php');
	
	// Create the tables:
	
	// Users:
	$sql = 'CREATE TABLE `'.$dbprefix.'users` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`name` TINYTEXT NOT NULL ,
		`password` TINYTEXT NOT NULL ,
		`email` TINYTEXT NOT NULL)';
	mq($sql);
	
	// Datatypes:
	$sql = 'CREATE TABLE `'.$dbprefix.'datatypes` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`name` TINYTEXT NOT NULL ,
		`description` TINYTEXT NOT NULL)';
	mq($sql);
	
	// Categories:
	$sql = 'CREATE TABLE `'.$dbprefix.'categories` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`name` TINYTEXT NOT NULL ,
		`description` TINYTEXT NOT NULL ,
		`id_datatype` INT NOT NULL,
		`id_category` INT NOT NULL)';
	mq($sql);

	// Options
	$sql = 'CREATE TABLE `'.$dbprefix.'options` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`name` TINYTEXT NOT NULL ,
		`description` TINYTEXT NOT NULL ,
		`type` TINYTEXT NOT NULL,
		`value` TEXT NOT NULL)';
	mq($sql);
	
	// Datatype - options
	$sql = 'CREATE TABLE `'.$dbprefix.'datatype_option` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`id_datatype` INT NOT NULL,
		`id_option` INT NOT NULL,
		`hasmany` TINYINT(1) NOT NULL)';
	mq($sql);
	
	// Values
	$sql = 'CREATE TABLE `'.$dbprefix.'values` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`id_item` INT NOT NULL,
		`id_option` INT NOT NULL,
		`value` TEXT NOT NULL)';
	mq($sql);
	
	// Items
	$sql = 'CREATE TABLE `'.$dbprefix.'items` (
		`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		`name` TINYTEXT NOT NULL ,
		`id_category` INT NOT NULL)';
	mq($sql);
    
	// Insert default values:
	$sql = 'INSERT INTO `'.$dbprefix.'users` (`name`, `password`, `email`) VALUES (\'admin\', \''.md5('admin').'\', \'example@example.com\');';
	mq($sql);
?>